#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void ShellSort(int arr[],int size)
{
	int gap = size;
	int temp = 0;
	int end = 0;
	while (gap > 1)
	{
		gap = gap / 3 + 1;
		for (int i = 0; i < size - gap; i++)
		{
			end = i;
			temp = arr[end +gap];
			while (end >= 0)
			{
				if (arr[end] > temp)
				{
					arr[end + gap] = arr[end];
					end = end - gap;
				}
				else
				{
					break;
				}
			}
			arr[end + gap] = temp;
		}
	}

}
int main()
{
	int arr[] = { 5,3,9,6,2,4,7,1,8 };
	int size = sizeof(arr) / sizeof(arr[0]);
	ShellSort(arr, size);
	for (int i = 0; i < size; i++)
	{
		printf("%d ", arr[i]);
	}

	return 0;
}